package com.zzr.demo.redis.controller;

import com.zzr.demo.redis.service.TimeLineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: xiaomi
 * @date: 2021/10/9
 * @description:
 */
@RestController
@RequestMapping("time/line/blog")
@Api(tags = "时间线：博客时间线记录和排序查询")
@Slf4j
public class BlogTimeLineController {

    @Autowired
    TimeLineService timeLineService;


    @GetMapping("/addItem/{name}/{score}")
    @ApiOperation("新增项目")
    public boolean addItem(@PathVariable("name") String name, @PathVariable("score") int score) {
        boolean b = timeLineService.addItem(name, score);
        return b;
    }

    @GetMapping("/size")
    @ApiOperation("获取集合大小")
    public long size() {
        long size = timeLineService.size();
        return size;
    }

    @GetMapping("/list/{pageNum}/{pageSize}")
    @ApiOperation("分页查询")
    public List<String> list(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize) {
        List<String> list = timeLineService.list(pageNum, pageSize);
        return list;
    }

    @GetMapping("/listByTimestamp/{pageNum}/{pageSize}/{min}/{max}")
    @ApiOperation("按照时间线分页查询")
    public List<String> listByTimestamp(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize,
                                        @PathVariable("min") int min, @PathVariable("max") int max) {
        List<String> list = timeLineService.listByScore(pageNum, pageSize, min, max);
        return list;
    }

}
